<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/8/11
 * Time: 14:11
 */

namespace app\api\model;


use think\Db;

class Banner extends BaseModel
{
    //隐藏字段
    protected $hidden = ['update_time','delete_time'];


    //关联模型
    public function items(){
        return $this->hasMany('BannerItem','banner_id','id');
    }
    public function items1(){

    }

    public static function getBannerByID($id)
    {    $banner = self::with(['items','items.img'])->find($id);
        return $banner;
    }


















    //学习
    /*public static function getBannerByID($id)
    {
        //TODO:根据Banner的id返回信息
//        原生
//        $result = Db::query("SELECT * from banner_item where banner_id = ?",[1]);
//        闭包
        $result = Db::table('banner_item')
            ->where(function ($query) use ($id){
                $query->where('banner_id','=',$id);
            })
            ->select();
//      封装all
        $result = Db::table('banner_item')
            ->where('banner_id','=',$id)
            ->all();
//    ORM Object Relation Mapping 对象关系映射模式
        //模型
        return $result;
    }*/

}